<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<!-- <script src='/Public/jquery.min.js'></script> -->
  <script src="https://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
  
	<script src='/Public/foundation/js/foundation.min.js'></script>
	<link rel="stylesheet" href="/Public/foundation/css/foundation.min.css">
  <script src='/Public/jquery.cityselect.js'></script>
  <script src='/Public/jquery.datetimepicker.full.js'></script>
  <link rel="stylesheet" href="/Public/jquery.datetimepicker.css">
   <script src="http://cdn.static.runoob.com/libs/foundation/5.5.3/js/vendor/modernizr.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<nav class="top-bar" data-topbar>
  <ul class="title-area">
    <li class="name">
      <h1><a href="#">后台管理</a></h1>
    </li>
  </ul>

  <section class="top-bar-section">
    <ul class="right">
      <li><a href=""><?php echo (session('name')); ?></a></li>
      <li><a href="<?php echo U('Login/doLogout');?>">退出</a></li>
    </ul>
  </section>
</nav>

<div class="small-2 columns">
<ul class="side-nav">
 <?php if(is_array($nav)): $i = 0; $__LIST__ = $nav;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><li><a href="<?php echo U($vo['url']);?>" target='<?php echo ($vo["target"]?"_blank":null); ?>'><?php echo ($vo["mname"]); ?></a></li><?php endforeach; endif; else: echo "" ;endif; ?>
    </ul>
</div>
<div class="small-10 columns">

    <style>
    input[type=checkbox] {
        width: 30px;
        height: 55px;
    }
	</style>
    <table id="point_ruleTb1">
        <thead>
        <tr>
            <td>姓名</td>
            <?php if(is_array($rule)): $i = 0; $__LIST__ = $rule;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$rule): $mod = ($i % 2 );++$i;?><td id="<?php echo ($rule["point_rule_id"]); ?>"><?php echo ($rule["rule_name"]); ?></td><?php endforeach; endif; else: echo "" ;endif; ?>
            <th>操作</th>
        </tr>
        </thead>

        <tbody>
        <?php if(is_array($nav1)): $i = 0; $__LIST__ = $nav1;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$nav1): $mod = ($i % 2 );++$i;?><tr id="row_<?php echo ($nav1["student_id"]); ?>">
                <td><input name="sname" class="es"style="width:6em;" readonly type="text" value=<?php echo ($nav1["sname"]); ?>></td>
                <?php if(is_array($nav1["roleall"])): $i = 0; $__LIST__ = $nav1["roleall"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$rule): $mod = ($i % 2 );++$i;?><td><input class="rows_<?php echo ($nav1["student_id"]); ?>" type="checkbox" value="<?php echo ($rule["point_rule_id"]); ?>" disabled></td><?php endforeach; endif; else: echo "" ;endif; ?>
                <td>
                    <button onclick="edit('<?php echo ($nav1["student_id"]); ?>')" class="button tiny edit ">编辑</button>
                    <button onclick="save('<?php echo ($nav1["student_id"]); ?>')" style="display: none;" class="button tiny save">提交</button>
                </td>
            </tr><?php endforeach; endif; else: echo "" ;endif; ?>
        </tbody>
    </table>
    <script>
        $('tbody td').click(function(){
            var index = $(this).index();
            var point_rule_id=$('thead tr td').eq(index).prop('id');
            //console.log(point_rule_id);
        });

        $('input[type=checkbox]').click(function () {
            var id = $(this).parent().parent().prop('id');
            //console.log(id);
        })

     function edit(rowid) {
         $('.rows_'+rowid).prop('disabled',false);
         $('#row_'+rowid+' .edit').hide();
         $('#row_'+rowid+' .save').show();
     }
     function save(id) {
         //扣分项id值
        a=$('.rows_'+id+':checked').map(function(){return $(this).val();}).get().join(",");
//console.log(a);
         var index = $(this).index();
            //var point_rule_id=$('thead tr td').eq(index).prop('id');

         $('.rows_' + id).prop('disabled', true);
         $('#row_' + id + ' .edit').show();
         $('#row_' + id + ' .save').hide();
         var ctime=new Date().getTime();
         var data = {
             student_id:id,
             point_rule_id:a,
         }
         console.log(data);
         $.post('<?php echo U("deduct");?>', data, function (data) {
                console.log(data);
				alert('扣分成功');
				window.location.href='<?php echo U("readCredit");?>';
         })
     }
    </script>


</div>

</body>
</html>